//
// Created by 高森森 on 2022/10/9.
//

#ifndef LEETCODE_SOLUTION_16_H
#define LEETCODE_SOLUTION_16_H
#include<bits/stdc++.h>
using namespace std;

class solution_16 {
public:
    //常规解法 超时
    int maxCount(int m, int n, vector<vector<int>>& ops) {
        vector<vector<int>> result(m, vector<int>(n, 0));
        for (int i = 0; i < ops.size(); i++) {
            int nx = ops[i][0];
            int ny = ops[i][1];
            for (int m = 0; m < nx; m++) {
                for (int n = 0; n < ny; n++) {
                    result[m][n]= result[m][n]+1;
                }
            }
        }
        int max = 0;
        int count = 0;
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++) {
                if (result[i][j] == max) {
                    count++;
                }
                if (result[i][j] > max) {
                    max = result[i][j];
                    count = 1;
                }
            }
        return count;
    }
    //正确解法 数学解法
    int maxCount2(int m, int n, vector<vector<int>>& ops) {
       int minx=m;
       int miny=n;
       for(int i=0;i<ops.size();i++){
           int x=ops[i][0];
           int y=ops[i][1];
           minx=min(minx,x);
           miny=min(miny,y);
       }
       return minx*miny;
    }
};


#endif //LEETCODE_SOLUTION_16_H
